import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import { resolve } from 'path'

// Locale 优化插件
function localeOptimizePlugin() {
  return {
    name: 'locale-optimize',
    generateBundle(options, bundle) {
      // 在生成 bundle 时可以进行额外的优化
      console.log('正在应用 locale 优化...');
    }
  }
}

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin(), localeOptimizePlugin()],
    build: {
      rollupOptions: {
        external: ['knex', 'better-sqlite3', '@journeyapps/sqlcipher', 'sqlite3', 'crypto-js', 'electron-updater', 'electron-log'],
        input: {
          index: resolve('src/main/index.js'),
          database: resolve('src/main/database.js'),
          updater: resolve('src/main/updater.js'),
          'locale-manager': resolve('src/main/locale-manager.js'),
          'key-manager': resolve('src/main/key-manager.js'),
          'sqlcipher-adapter': resolve('src/main/sqlcipher-adapter.js'),
          'key-obfuscator': resolve('src/main/key-obfuscator.js')
        }
      }
    }
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src')
      }
    }
  }
})